package com.t235.gc.order.controller;

import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import com.t235.gc.AjaxResult;
import com.t235.gc.entity.*;
import com.t235.gc.mapper.UsersMapper;
import com.t235.gc.order.service.*;
import com.t235.gc.vo.GoodsOrderVo;
import com.t235.gc.vo.HomeRecyclingOrderVo;
import com.t235.gc.vo.RecyclingOrderVo;
import io.swagger.annotations.Api;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import io.swagger.annotations.ApiOperation;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;
import java.util.List;

@Api
@RestController
@RequestMapping("/order")
public class DemoController {
    @Resource
    private UsersMapper usersMapper;
    @Autowired
    private RecyclingOrderService recyclingOrderService;
    @Autowired
    private HomeRecyclingOrderService homeRecyclingOrderService;
    @Autowired
    private HomeRecyclingDetailOrderService homeRecyclingDetailOrderService;
    @Autowired
    private GoodsOrderService goodsOrderService;
    @Autowired
    private VenuesService venuesService;
    @Autowired
    private PartnersService partnersService;
    @Autowired
    private SysManagerService sysManagerService;
    @Autowired
    private RecyclingDetailOrderService recyclingDetailOrderService;

    @GetMapping("/hello")
    @ApiOperation(value = "hello world test",httpMethod = "GET")
    public String hello() {
        return "hello world " + usersMapper.selectByPrimaryKey(1201581319114785L).getNickName();
    }

    @GetMapping("/getListByOrderId")
    @ApiOperation(value="查询垃圾投递手风琴列表",httpMethod = "GET")
    public AjaxResult getListByOrderId(String orderId){
        List<GarbageRecyclingOrder> list=recyclingOrderService.getListByOrderId(orderId);
        return AjaxResult.success(list);
    }
    @GetMapping("/getHomeRecyclingOrderListByOrderId")
    @ApiOperation(value="查询上门回收手风琴列表",httpMethod = "GET")
    public AjaxResult getHomeRecyclingOrderListByOrderId(String orderId){
        List<HomeRecyclingOrder> list=homeRecyclingOrderService.getListByOrderId(orderId);
        return AjaxResult.success(list);
    }
    @PostMapping("/getRecyclingOrderList")
    @ApiOperation(value = "查询垃圾投递订单",httpMethod = "POST")
    public AjaxResult getRecyclingOrderList(RecyclingOrderVo vo,@RequestParam(value="page") Integer page,@RequestParam(value="limit") Integer pageSize){
        PageHelper.startPage(page,pageSize);
        List<GarbageRecyclingOrder> list=recyclingOrderService.getList(vo);
        PageInfo<GarbageRecyclingOrder> pageInfo=new PageInfo<>(list);
        pageInfo.setSize(recyclingOrderService.getCount(vo));
        return AjaxResult.success(pageInfo);
    }


    @PostMapping("/getHomeRecyclingOrderList")
    @ApiOperation(value = "查询上门回收垃圾订单",httpMethod = "POST")
    public AjaxResult getHomeRecyclingOrderList(HomeRecyclingOrderVo vo, @RequestParam(value="page") Integer page, @RequestParam(value="limit") Integer pageSize){
        PageHelper.startPage(page,pageSize);
        List<HomeRecyclingOrder> list=homeRecyclingOrderService.getList(vo);
        PageInfo<HomeRecyclingOrder> pageInfo=new PageInfo<>(list);
        pageInfo.setSize(homeRecyclingOrderService.getCount(vo));
        return AjaxResult.success(pageInfo);
    }


    @GetMapping("/getDetailList")
    @ApiOperation(value = "查询上门回收垃圾订单里的物品列表",httpMethod = "GET")
    public AjaxResult getDetailList(String orderId){
        List<HomeRecyclingDetailOrder> list=homeRecyclingDetailOrderService.getList(orderId);
        PageInfo<HomeRecyclingDetailOrder> pageInfo=new PageInfo<>(list);
        pageInfo.setSize(homeRecyclingDetailOrderService.getCount(orderId));
        return AjaxResult.success(pageInfo);
    }

    @GetMapping("/getRecyclingOrderDetailList")
    @ApiOperation(value = "查询垃圾投递订单里的物品列表",httpMethod = "GET")
    public AjaxResult getRecyclingOrderDetailList(String orderId){
        List<GarbageRecyclingDetailOrder> list=recyclingDetailOrderService.getList(orderId);
        PageInfo<GarbageRecyclingDetailOrder> pageInfo=new PageInfo<>(list);
        pageInfo.setSize(recyclingDetailOrderService.getCount(orderId));
        return AjaxResult.success(pageInfo);
    }

    @PostMapping("/del")
    @ApiOperation(value = "删除",httpMethod = "POST")
    public AjaxResult del(String orderId){
        if(homeRecyclingOrderService.del(orderId)>0){
            return AjaxResult.success();
        }
        return AjaxResult.error();
    }


    @PostMapping("/getGoodsOrderList")
    @ApiOperation(value = "查询商品销售订单",httpMethod = "POST")
    public AjaxResult getGoodsOrderList(GoodsOrderVo vo,@RequestParam(value="page") Integer page, @RequestParam(value="limit") Integer pageSize){
        PageHelper.startPage(page,pageSize);
        List<GoodsOrder> list=goodsOrderService.getList(vo);
        PageInfo<GoodsOrder> pageInfo=new PageInfo<>(list);
        pageInfo.setSize(goodsOrderService.getCount(vo));
        return AjaxResult.success(pageInfo);
    }
    @GetMapping("/getVenuesList")
    @ApiOperation(value="查询设备场地列表")
    public Object getVenuesList(){
        return venuesService.getList();
    }
    @GetMapping("/getPartnersList")
    @ApiOperation(value="查询合伙人列表")
    public Object getPartnersList(){
        return partnersService.getList();
    }
    @GetMapping("/getManagerList")
    @ApiOperation(value="查询运营商，分拣中心列表")
    public Object getManagerList(Integer managerType){
        return sysManagerService.getList(managerType);
    }
}
